// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;

const int N = 3e5+50, M = 5;

int t, n;

LL dp[N][M];

int a[N], b[N];

inline void update(LL &a, LL b) {
    a = min(a, b);
}

int main(int argc, char const *argv[]) {
    // code
    scanf("%d", &t);
    for (int kk=0; kk<t; ++kk) {
        scanf("%d", &n);
        for (int i=1; i<=n; ++i)
            scanf("%d%d", &a[i], &b[i]);
        for (int i=0; i<=n; ++i)
            for (int j=0; j<M; ++j)
                dp[i][j] = 1e18 + 50;
        for (int i=0; i<M; ++i)
            dp[1][i] = 1LL * i * b[1];
        // dbg(dp[1][4]);
        for (int i=1; i<n; ++i)
            for (int j=0; j<M; ++j) {
                for (int k=0; k<M; ++k)
                    if (a[i] + j != a[i+1] + k) {
                        // if (i == 1 && k == 0) {
                        //     dbg(i, j, k, dp[i][j] + 1LL * k * b[i+1], dp[i][j]);
                        // }
                        update(dp[i+1][k], dp[i][j] + 1LL * k * b[i+1]);
                    }
            }
        // dbg(dp[1][1]);
        LL ans = 1e18 + 50;
        for (int j=0; j<M; ++j)
            update(ans, dp[n][j]);
        printf("%lld\n", ans);
    }
    return 0;
}
